Regular Expression help

what is the proper way using door support regular expressions to find all matches(string) that exclude key words?

 

/.*(/(?!sale|search|lot|login).*)?/.*

 


EHcnck - Fri Oct 13 15:09:37 EDT 2017

Re: Regular Expression help
Mike.Scharnow - Sun Oct 15 05:40:55 EDT 2017

Independent of DOORS, when creating a concept with regular expressions, it is always quite difficult to work with "negative" expressions.

If you say, "find everything that is not "lot"" and you search in "camelot", in theory you get a) "" (beginning of string),, b) "c", c) "ca", e) "cam", f) "came", g) "" (end of string) in a non greedy expression and a) "came" and b) empty string (end of string) in a greedy expression.

If you want to find all Object Texts that do not contain any of the key words, it is besser to define

Regexp re = regexp2 "/(sale|search|lot|login)/"

and work with

 if not re o."Object Text""" then

 

Re: Regular Expression help
EHcnck - Sun Oct 15 13:23:17 EDT 2017

Mike.Scharnow - Sun Oct 15 05:40:55 EDT 2017

Independent of DOORS, when creating a concept with regular expressions, it is always quite difficult to work with "negative" expressions.

If you say, "find everything that is not "lot"" and you search in "camelot", in theory you get a) "" (beginning of string),, b) "c", c) "ca", e) "cam", f) "came", g) "" (end of string) in a non greedy expression and a) "came" and b) empty string (end of string) in a greedy expression.

If you want to find all Object Texts that do not contain any of the key words, it is besser to define

Regexp re = regexp2 "/(sale|search|lot|login)/"

and work with

 if not re o."Object Text""" then

 

I'm trying not to rework all my existing functions I need to pass the regx as a string.

Re: Regular Expression help
Mike.Scharnow - Sun Oct 15 16:03:57 EDT 2017

EHcnck - Sun Oct 15 13:23:17 EDT 2017

I'm trying not to rework all my existing functions I need to pass the regx as a string.

that might become difficult. Can you give an example of what shall be recognized how and how your existing functions currently work?

Re: Regular Expression help
EHcnck - Sun Oct 15 21:36:59 EDT 2017

Mike.Scharnow - Sun Oct 15 16:03:57 EDT 2017

that might become difficult. Can you give an example of what shall be recognized how and how your existing functions currently work?

trying to exclude Modules names with CDER but in the future may include additional keywords XXXX-CDER-XXXX-XXXX [X] maybe [A-Za-z0-9]

Re: Regular Expression help
Mike.Scharnow - Mon Oct 16 04:24:25 EDT 2017

EHcnck - Sun Oct 15 21:36:59 EDT 2017

trying to exclude Modules names with CDER but in the future may include additional keywords XXXX-CDER-XXXX-XXXX [X] maybe [A-Za-z0-9]

Well, the expression to FIND these modules is clear, can be e.g.

Regexp re = regexp2 "-(CDER|LALA|LULU)-"
if re upper(s) then..

So, if you could rewrite your functions to include a mode "does not match", life would be rather easy.

if !re upper(s)..

Alternatively, if your naming convention for modules is very strict, you might try something like

re = regexp2 "^....-[^C][^D][^E][^R]-"

(the first 4 characters are anything, then a dash, then not a C, then not a D, ....but with this approach you will probably have too many false negatives, als XXXX-DDER-XXXX-XXXX would also match.

 

The only other thing I can currently think of is 

re = regexp2 "^....-([^C]...|C[^D]..|CD[^E].|CDE[^R])-"

which seems to work for CDER, but I'm not sure how to expand this with multiple keywords..

 

Am I thinking too complicated? Has anyone else a better idea?

Re: Regular Expression help
EHcnck - Mon Oct 16 07:51:58 EDT 2017

Mike.Scharnow - Mon Oct 16 04:24:25 EDT 2017

Well, the expression to FIND these modules is clear, can be e.g.

Regexp re = regexp2 "-(CDER|LALA|LULU)-"
if re upper(s) then..

So, if you could rewrite your functions to include a mode "does not match", life would be rather easy.

if !re upper(s)..

Alternatively, if your naming convention for modules is very strict, you might try something like

re = regexp2 "^....-[^C][^D][^E][^R]-"

(the first 4 characters are anything, then a dash, then not a C, then not a D, ....but with this approach you will probably have too many false negatives, als XXXX-DDER-XXXX-XXXX would also match.

 

The only other thing I can currently think of is 

re = regexp2 "^....-([^C]...|C[^D]..|CD[^E].|CDE[^R])-"

which seems to work for CDER, but I'm not sure how to expand this with multiple keywords..

 

Am I thinking too complicated? Has anyone else a better idea?

So here is my function, I parse the entire DB put the module names into my skip list then I filter out what I don't need base on "Regx" so I currently only want the modules that are in Folder "A" and along with that they must not have "CDER" in its name.  the below function can't change.. meaning it needs to parse the data off the "Regx" because my condition many change today/tomorrow etc.

 

/****************************
        getItemizedList
****************************/
Skip getItemizedList(Skip Skp, string Regx) {
        Skip sk = createString()
        Module m
        string Value = null
        for m in Skp do {
                Value = (string key Skp)
                if (matches(Regx, Value)) {
                        put(sk, rootName_ m, m, true)
                }
        }
        return sk
} // getItemizedList

 

Re: Regular Expression help
O.Wilkop - Mon Oct 16 08:45:16 EDT 2017

I don't think it is possible to create a regex that excludes something like this... can't you create a workaround like:

 

Skip getItemizedList(Skip Skp, string Regx, bool bInclude) {
        Skip sk = createString()
        Module m
        string Value = null
        for m in Skp do {
                Value = (string key Skp)
                if (matches(Regx, Value) == bInclude) {
                        put(sk, rootName_ m, m, true)
                }
        }
        return sk
}

Skip getItemizedList(Skip Skp, string Regx) {
        return getItemizedList(Skp, Regx, true);
}

that way you don't have to change any of your existing code, but can optionally pass a third parameter "include=false" if you want to exclude a module instead.